<template>
  <el-card>
    <div slot="header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item><a href="/">订单管理</a></el-breadcrumb-item>
        <el-breadcrumb-item><a href="/">订单列表</a></el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- 筛选区域 -->
    <div class="filter-bar">
      <div class="l-form">
        <el-form
          :model="searchForm"
          label-width="80px"
          size="mini"
          :inline="true"
        >
          <el-form-item label="用户Id">
            <el-input v-model="searchForm.user_id" size="small"></el-input>
          </el-form-item>
          <el-form-item label="支付状态">
            <el-select
              v-model="searchForm.pay_status"
              placeholder="请选择"
              size="small"
            >
              <el-option label="全部状态" value=""> </el-option>
              <el-option label="已付款" value="1"> </el-option>
              <el-option label="未付款" value="0"> </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="发货状态">
            <el-select
              v-model="searchForm.is_send"
              placeholder="请选择"
              size="small"
            >
              <el-option value="" label="全部状态"> </el-option>
              <el-option value="是" label="是"> </el-option>
              <el-option value="否" label="否"> </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="">
            <el-button type="primary" size="small" @click="getOrderList"
              >查询</el-button
            >
            <el-button type="danger" size="small" @click="resetSearch"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
    <!-- 表格区域 -->
    <div class="tab-list">
      <el-table :data="orderList" style="width: 100%">
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="180">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" align="center">
        </el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="180">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货">
          <template slot-scope="scope">
            <el-button
              type="success"
              circle
              size="small"
              v-if="scope.row.is_send === '是'"
              icon="el-icon-circle-check"
            ></el-button>
            <el-button
              type="danger"
              circle
              size="small"
              v-else
              icon="el-icon-circle-close"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="180">
          <template slot-scope="scope">
            {{ scope.row.create_time | formateTime }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="editOrder(scope.row)"
            ></el-button>
            <el-button
              size="mini"
              type="success"
              icon="el-icon-location"
              @click="seeExpress(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchForm.pagenum"
      :page-sizes="[10, 20, 30]"
      :page-size="searchForm.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>

    <!-- 弹框 -->
    <el-dialog title="物流信息" :visible.sync="dialogVisible" width="60%">
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in expressInfo"
          :key="index"
          :timestamp="item.time"
          reverse="false"
        >
          {{ item.context }}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>

    <!-- 编辑弹框 -->
    <el-dialog
      title="编辑物流信息"
      :visible.sync="editdialogVisible"
      width="60%"
    >
      <el-form
        :model="addresform"
        :rules="addresformRules"
        ref="addresform"
        label-width="120px"
      >
        <el-form-item label="省市县" prop="addres_list">
          <el-cascader
            v-model="addresInfo.addres_list"
            :options="cityData"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="地址" prop="detail_info">
          <el-input v-model="addresInfo.detail_info" type="textarea"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addresSubmit">提交</el-button>
      </span>
    </el-dialog>
  </el-card>
</template>

<script>
// 导入省市县联动
import cityData from "@/utiles/citydata";
let defaultForm = {
  user_id: "",
  pagenum: 1,
  pagesize: 10,
  pay_status: "",
  is_send: ""
};
export default {
  data() {
    return {
      searchForm: { ...defaultForm },
      total: 0,
      orderList: [],
      dialogVisible: false,
      expressInfo: [], //物流信息
      editdialogVisible: false,
      addresInfo: { addres_list: [], detail_info: "" },
      cityData,
      addresformRules: {
        addres_list: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    async getOrderList() {
      let { data: res } = await this.$axios.get("orders", {
        params: this.searchForm
      });
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.orderList = res.data.goods;
      this.total = res.data.total;
    },
    // 重置
    resetSearch() {
      this.searchForm = { ...defaultForm };
      this.getOrderList();
    },
    handleSizeChange(val) {
      this.searchForm.pagesize = val;
      this.getOrderList();
    },
    handleCurrentChange(val) {
      this.searchForm.pagenum = val;
      this.getOrderList();
    },
    // 查看物流
    async seeExpress(row) {
      if (row.is_send === "是") {
        this.dialogVisible = true;
        // let { data: res } = await this.$axios.get("/kuaidi/1106975712662");
        // if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
        this.expressInfo = [
          {
            time: "2018-05-10 09:39:00",
            ftime: "2018-05-10 09:39:00",
            context: "已签收,感谢使用顺丰,期待再次为您服务",
            location: ""
          },
          {
            time: "2018-05-10 08:23:00",
            ftime: "2018-05-10 08:23:00",
            context:
              "[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件",
            location: ""
          },
          {
            time: "2018-05-10 07:32:00",
            ftime: "2018-05-10 07:32:00",
            context: "快件到达 [北京海淀育新小区营业点]",
            location: ""
          },
          {
            time: "2018-05-10 02:03:00",
            ftime: "2018-05-10 02:03:00",
            context:
              "快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]",
            location: ""
          },
          {
            time: "2018-05-09 23:05:00",
            ftime: "2018-05-09 23:05:00",
            context: "快件到达 [北京顺义集散中心]",
            location: ""
          },
          {
            time: "2018-05-09 21:21:00",
            ftime: "2018-05-09 21:21:00",
            context: "快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]",
            location: ""
          },
          {
            time: "2018-05-09 13:07:00",
            ftime: "2018-05-09 13:07:00",
            context: "顺丰速运 已收取快件",
            location: ""
          },
          {
            time: "2018-05-09 12:25:03",
            ftime: "2018-05-09 12:25:03",
            context: "卖家发货",
            location: ""
          },
          {
            time: "2018-05-09 12:22:24",
            ftime: "2018-05-09 12:22:24",
            context: "您的订单将由HLA（北京海淀区清河中街店）门店安排发货。",
            location: ""
          },
          {
            time: "2018-05-08 21:36:04",
            ftime: "2018-05-08 21:36:04",
            context: "商品已经下单",
            location: ""
          }
        ];
      } else {
        this.$notify.warning({
          title: "物流",
          message: "商品未发货，无物流信息",
          type: "success"
        });
      }
    },
    // 编辑
    editOrder(row) {
      this.editdialogVisible = true;
    },
    addresSubmit() {
      this.editdialogVisible = false;
    }
  }
};
</script>

<style lang="less" scoped>
</style>